<?php
/**
 * Created by PhpStorm.
 * User: Dalei
 * Date: 2018/8/26
 * Time: 22:40
 */

namespace Home\Controller;

/*
 * 寻找简历接口
 *
 * @found   主页面接口
 * @place_cartridge 找简历/地区筛选值接口
 * @reg     地区筛选接口
 * @job     职位筛选接口
 * @find    搜索接口
 * */
class TofyrController extends HomeController{
    /*
     * 找简历/主页面接口
     *
     * @return varchar picture      头像
     * @return varchar name         姓名
     * @return varchar gender       性别
     * @return varchar num         页码数
     * @return varchar mobile       手机
     * @return int age              年龄
     * @return varchar education    学历
     * @return varchar worktime     工作经验
     * @return varchar region       期望地区
     * @return varchar jobinten     期望工作
     * @['resume']      简历信息表
     * */
    public function found(){
        $resu = array('code' => 1,'msg' => '简历信息查询成功!','data' => array());
        $num = $_POST['num'] ? $_POST['num']:'1';
        $list = M('resume')
            ->limit((1 - 1)*10,$num*10)
            ->field('picture,name,gender,age,education,worktime,region,jobinten,year,mobile')
            ->select();//查询符合条件的数据记录
        if($list){
            $resu['data'] =$list;
        }else{
            $resu['msg'] ='简历信息查询失败!';
        }
        $this -> ajaxReturn($resu);
    }
    /*
     * 找简历/地区筛选值接口
     *
     * @params varchar jobfield       职位地区
     * @['company']     数据库表中的公司信息表
     * */
    public function place_cartridge(){
        $resu = array('code' => 1,'msg' => '数据查询成功!','data' => array());
        //通过前台点击事件来获取地区具体信息,以便于处查询数据库,并且筛选相应字段
        $list = M('resume')
            ->group(true)
            ->field('region')
            ->select();
        if($list){
            $resu['data'] =$list;
        }else{
            $resu['msg'] ='数据查询失败!';
        }
        $this->ajaxReturn($resu);
    }
    /*
     * 找简历/职位筛选值接口
     *
     * @params varchar jobfield       职位地区
     * @['company']     数据库表中的公司信息表
     * */
    public function job_cartridge(){
        $resu = array('code' => 1,'msg' => '数据查询成功!','data' => array());
        //通过前台点击事件来获取地区具体信息,以便于处查询数据库,并且筛选相应字段
        $list = M('resume')
            ->group(true)
            ->field('title')
            ->select();
        if($list){
            $resu['data'] =$list;
        }else{
            $resu['msg'] ='数据查询失败!';
        }
        $this->ajaxReturn($resu);
    }
    /*
     * 找简历/职位和地区筛选接口
     *
     * @params varchar jobinten     职位信息
     * @return varchar picture     头像
     * @return varchar name        姓名
     * @return varchar gender      性别
     * @return int age             年龄
     * @return int num             页码数
     * @return varchar education   学历
     * @return varchar worktime    工作经验
     * @return varchar region      期望地区
     * @return varchar jobinten    期望职位
     * @['resume']      简历信息表
     * */
    public function job(){
        $resu = array('code' => 1,'msg' => '相关职位信息查询成功!','data' => array());
        $num = $_POST['num'] ? $_POST['num']:'1';
        $title = $_POST['title'];
        $region = $_POST['region'];
        $arr = array('region' => $region);//地区
        $brr = array('title' => $title);//职位标题
        $crr = array($arr,$brr);
        if(empty($title) && empty($region)){
            $list = M('resume')
                ->limit((1 - 1)*10,$num*10)
                ->field('picture,name,gender,age,education,worktime,region,jobinten,year')
                ->select();
            if($list){
                $resu['data'] = $list;
            }else{
                $resu['code'] = 2;
                $resu['msg'] = '还没有招聘信息!';
            }
        }else{
            if(empty($title) or empty($region)){
                if($title){
                    $list = M('resume')
                        ->where($brr)
                        ->limit((1 - 1)*10,$num*10)
                        ->field('picture,name,gender,age,education,worktime,region,jobinten,year')
                        ->select();
                    if($list){
                        $resu['data'] = $list;
                    }else{
                        $resu['code'] = 2;
                        $resu['msg'] = '该地区还没有该职位!';
                    }
                }else if($region){
                    $list = M('resume')
                        ->where($arr)
                        ->limit((1 - 1)*10,$num*10)
                        ->field('picture,name,gender,age,education,worktime,region,jobinten,year')
                        ->select();
                    if($list){
                        $resu['data'] = $list;
                    }else{
                        $resu['code'] = 2;
                        $resu['msg'] = '该地区还没有该职位!';
                    }
                }
            }else{
                $list = M('resume')
                    ->where($crr)
                    ->limit((1 - 1)*10,$num*10)
                    ->field('picture,name,gender,age,education,worktime,region,jobinten,year')
                    ->select();
                if($list){
                    $resu['data'] = $list;
                }else{
                    $resu['code'] = 2;
                    $resu['msg'] = '相关职位信息查询失败!';
                }
            }
        }
        $this->ajaxReturn($resu);
    }
    /*
     * 找简历/搜索接口
     *
     * @params varchar jobinten     职位信息
     * @return varchar picture     头像
     * @return varchar name        姓名
     * @return varchar gender      性别
     * @return int age             年龄
     * @return varchar education   学历
     * @return varchar worktime    工作经验
     * @return varchar region      期望地区
     * @return varchar keyword     搜索框内容
     * @['resume']      简历信息表
     * */
    public function find(){
        $resu = array('code' => 1,'msg' => '数据查询成功!','data' => array());
        //先使用模糊查询将值赋给变量$data
        $data['jobinten']=array("like","%".$_POST['keyword']."%");
        $list = M('resume')//主要是公司通过岗位来查询简历
            ->where($data)
            ->field('picture,name,gender,age,education,worktime,region,jobinten,year')
            ->select();
        if($list){
            $resu['data'] = $list;
        }else{
            $resu['msg']  ='数据查询失败!';
        }
        $this->ajaxReturn($resu);
    }
}